<template>
	<view class="home">
		<!-- 搜索 -->
		<view class="search">
			<image src="../../static/search_a.png"></image>
			<input class="input_search" confirm-type="search" @confirm="Onsearch" placeholder="搜索医生"
				maxlength="30" placeholder-class="placeholderClass" />
		</view>
		<!-- 轮播图 -->
		<view class="shuttle">
			<uni-swiper-dot :info="rotationList" :current="bannerCurrent" mode="round" :dotsStyles="dotsStyles">
				<swiper class="shuttle_swiper" :autoplay="true" :interval="3000" :circular="true"
					@change="swiperChange">
					<swiper-item class="" v-for="(item, index) in rotationList" :key="index">
						<image @click="goNext(item.url,false)" class="shuttle_img" :src="item.img"></image>
					</swiper-item>
				</swiper>
			</uni-swiper-dot>
		</view>
		<!-- 轮播文字广告 -->
		<view class="notice">
			<an-notice-bar :text="noticeMsg" @Onbar="Onbar" :showSerial="'false'"></an-notice-bar>
		</view>
		<!-- 快递通道 -->
		<view class="passageway">
			<view class="title">
				<view class="font17 font-323232 font-b">快递通道</view>
				<!-- <text class="font-7d766b font14">更多 ></text> -->
			</view>
			<view class="passa_geway">
				<view class="passageway_bos bg-cover" :style="{'background-image':'url('+item.img+')'}"
					@click="goNext(item.url,false)" v-for="(item, index) in passaList" :key="index">
					<!-- <view class="passageway_box">
						<view class="font17 font-323232 font-b">{{item.name}}</view>
						<text class="font-646464 font14">{{item.title}}</text>
					</view>
					<image :src="item.img"></image> -->
				</view>
			</view>
		</view>
		<!-- 分类 -->
		<view class="ification">
			<view v-for="(item, index) in ificationList" :key="index" @click="goNext(item.url,false)">
			<!-- 	<view class="ification_box">
					<image :src="item.img"></image>
				</view> -->
				<image class="ification_box" :src="item.img"></image>
				<view class="font-323232 font13 flex-row-center">{{item.name}}</view>
			</view>
		</view>
		<!-- 导航切换 -->
		<view class="home_nav">
			<view class="homelife_head">
				<view v-for="(item,index) in headlist" :key="index" class="container_headbox" @click="Onhead(item)">
					<text :class="headindex == item.id?'head_titlea':'head_titleb'">{{item.name}}</text>
					<view v-if="headindex == item.id"></view>
				</view>
			</view>
			<view class="department_bos">
				<view class="department_box" v-for="(item, index) in departmentList" :key="index" @click="goNext(item.url,false)">
					<image :src="item.img"></image>
					<view class="font-323232 font13 ellipsis">{{item.name}}</view>
				</view>
			</view>
		</view>
		<!-- 患教中心 -->
		<view class="educa">
			<view class="educa_title flex-row-between">
				<view class="flex-row-start">
					<view class="educa_day">今日推荐</view>
					<view class="font-323232 font14 font-b font-323232">患教中心</view>
				</view>
				<view class="font12 educa_morea flex-row-start" @click="goNext('/pagesA/home/educaList',false)">
					<text class="font-969696">查看更多</text>
					<image src="../../static/my/morea.png" mode=""></image>
				</view>
			</view>
			<block v-for="(item, index) in educaList" :key="index">
				<view class="brand-item flex-row-start"
					@click="goNext('/pagesA/info/newsinfo?type=universal&id='+item.id, false)">
					<view class="brand-info flex-column-between">
						<view class="font14">{{item.name}}</view>
						<view class="font12 font-969696">{{item.keyword}}</view>
						<view class="flex-row-between">
							<view class="font12 font-969696">{{item.initial_volume}}阅读</view>
							<view class="font12 font-969696">{{item.createtime}}</view>
						</view>
					</view>
					<view class="brand-logo bg-cover flex-row-center"
						:style="{backgroundImage: 'url(' + item.img + ')'}">
						<image v-if="item.is_video==1" src="../../static/home/video.png" mode=""></image>
					</view>
				</view>
			</block>
		</view>
		<ComTabBar :selected="0"></ComTabBar>
	</view>

</template>

<script>
	import AnNoticeBar from '@/components/an-notice-bar/an-notice-bar.vue';
	import ComTabBar from '@/components/ComTabBar.vue';
	export default {
		components: {
			ComTabBar,
			AnNoticeBar
		},
		data() {
			return {
				loadif: false, //数据加载
				//轮播数据
				rotationList: [],
				//轮播参数
				bannerCurrent: 0,
				dotsStyles: {
					width: 3,
					height: 3,
					backgroundColor: 'rgba(51, 51, 51, .3)',
					border: '1px rgba(51, 51, 51, .3) solid',
					selectedBackgroundColor: '#6bcbb6',
					selectedBorder: '1px #6bcbb6 solid'
				},
				noticeMsg: [], //公告咨询
				passaList: [], //快捷通道
				ificationList: [], //分类

				//切换头部
				headlist: [],
				headindex: 1, //下标显示
				//数据切换
				departmentList: [],
				educaList: [], //患教中心数据
			}
		},
		onShow: function() {
			wx.hideTabBar()
		},
		onLoad() {
			//接口
			this.Onhttp()
		},
		methods: {
			//接口
			Onhttp() {
				// let Project = new Promise((resolved, rejected) => {})
				let that = this
				//轮播
				let banner = new Promise((resolved, rejected) => {
					that.$Http({
						url: 'banner',
						data: {},
						token: false
					}).then(res => {
						if (res.code == 1) {
							res.data.forEach(item => {
								item.img = that.$store.state.http_img + item.img
							})
							that.rotationList = res.data
						}
						resolved(true)
					});
				})

				//公告咨询
				let dynamic = new Promise((resolved, rejected) => {
					that.$Http({
						url: 'dynamic',
						data: {
							is_recommend: 1
						},
						token: false
					}).then(res => {
						if (res.code == 1) {
							that.noticeMsg = res.data.data;
						}
						resolved(true)
					});
				})

				//快捷通道
				let fastTrack = new Promise((resolved, rejected) => {
					that.$Http({
						url: 'fastTrack',
						data: {},
						token: false
					}).then(res => {
						if (res.code == 1) {
							res.data.forEach(item => {
								item.img = that.$store.state.http_img + item.img
							})
							that.passaList = res.data
						}
						resolved(true)
					});
				})

				//快捷导航
				let Project = new Promise((resolved, rejected) => {
					that.$Http({
						url: 'fastNavigation',
						data: {},
						token: false
					}).then(res => {
						if (res.code == 1) {
							res.data.forEach(item => {
								item.img = that.$store.state.http_img + item.img
							})
							that.ificationList = res.data
						}
						resolved(true)
					});
				})

				//常用快捷分类
				let quickType = new Promise((resolved, rejected) => {
					that.$Http({
						url: 'quickType',
						data: {},
						token: false
					}).then(res => {
						if (res.code == 1) {
							that.headlist = res.data
							that.headindex = res.data[0].id
							//据分类获取常用快捷入口
							that.$Http({
								url: 'quickFast',
								data: {
									quick_type: res.data[0].id
								},
								token: false
							}).then(res1 => {
								if (res1.code == 1) {
									res1.data.forEach(item => {
										item.img = that.$store.state.http_img + item.img
									})
									that.departmentList = res1.data
								}
								resolved(true)
							});
						}
					});
				})

				//患教中心
				let universal = new Promise((resolved, rejected) => {
					that.$Http({
						url: 'universal',
						data: {
							is_recommend: 1
						},
						token: false
					}).then(res => {
						if (res.code == 1) {
							res.data.data.forEach(item => {
								item.img = that.$store.state.http_img + item.img
								item.createtime = that.$base.formatTime(new Date(item.createtime *
									1000), "yyyy/MM/dd")
							})
							that.educaList = res.data.data
						}
						resolved(true)
					});
				})

				Promise.all([banner, dynamic, fastTrack, Project, quickType, universal]).then((result) => {
					that.loadif = true
				}).catch((error) => {})


			},
			// 轮播图change
			swiperChange(e) {
				this.bannerCurrent = e.detail.current;
			},
			//搜索
			Onsearch(e) {
				uni.navigateTo({
					url: '/pagesA/ask/sechlist?sech=' + e.detail.value
				});
			},
			//切换
			Onhead(res) {
				this.headindex = res.id
				this.$Http({
					url: 'quickFast',
					data: {
						quick_type: res.id
					},
					token: false
				}).then(res1 => {
					if (res1.code == 1) {
						res1.data.forEach(item => {
							item.img = this.$store.state.http_img + item.img
						})
						this.departmentList = res1.data
					}
				});
			},
			//详情
			Onbar(e) {
				uni.navigateTo({
					url: '/pagesA/info/newsinfo?type=dynamic&id=' + e.id
				});
			},
			// 路由跳转: tag默认false,tag=true跳到tabBar页面
			goNext(url, tag) {
				if (tag) {
					uni.switchTab({
						url: url
					});
				} else {
					uni.navigateTo({
						url: url
					});
				}
			},
		}
	}
</script>

<style lang="less">
	@import url("style.less");
	page{
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
</style>
